#ifndef __UNIPLAY_STEP_MOTOR_H_
#define __UNIPLAY_STEP_MOTOR_H_

#include "MyApplication.h"
#define SET_Motor_A HAL_GPIO_WritePin(Step_Motor_A_GPIO_Port,Step_Motor_A_Pin,GPIO_PIN_SET)
#define CLR_Motor_A HAL_GPIO_WritePin(Step_Motor_A_GPIO_Port,Step_Motor_A_Pin,GPIO_PIN_RESET)

#define SET_Motor_B HAL_GPIO_WritePin(Step_Motor_B_GPIO_Port,Step_Motor_B_Pin,GPIO_PIN_SET)
#define CLR_Motor_B HAL_GPIO_WritePin(Step_Motor_B_GPIO_Port,Step_Motor_B_Pin,GPIO_PIN_RESET)

#define SET_Motor_C HAL_GPIO_WritePin(Step_Motor_C_GPIO_Port,Step_Motor_C_Pin,GPIO_PIN_SET)
#define CLR_Motor_C HAL_GPIO_WritePin(Step_Motor_C_GPIO_Port,Step_Motor_C_Pin,GPIO_PIN_RESET)

#define SET_Motor_D HAL_GPIO_WritePin(Step_Motor_D_GPIO_Port,Step_Motor_D_Pin,GPIO_PIN_SET)
#define CLR_Motor_D HAL_GPIO_WritePin(Step_Motor_D_GPIO_Port,Step_Motor_D_Pin,GPIO_PIN_RESET)

#define Circle_Set_Value    (uint8_t)3  //转动圈数

//定义枚举类型
//电机状态
typedef enum
{
    Start_Status = (uint8_t)0,
    Stop_Status  = (uint8_t)1
}Status_t;

//方向
typedef enum
{
    Forward_Status = (uint8_t)0,
    Reverse_Status = (uint8_t)1,
}Direction_t;

//速度等级
//调整ARR的值，改变输出脉冲频率，初始化频率为10KHz，0.1ms
typedef enum
{
    Speed_1 = (uint8_t)100,
    Speed_2 = (uint8_t)90,
    Speed_3 = (uint8_t)80,
    Speed_4 = (uint8_t)70,
    Speed_5 = (uint8_t)60,
    Speed_6 = (uint8_t)50,  //50*0.1ms = 5ms，初始化默认
    Speed_7 = (uint8_t)40,
    Speed_8 = (uint8_t)30,
    Speed_9 = (uint8_t)20
}Speed_t;

//加减速
typedef enum
{
    Speed_up   = (uint8_t)0,
    Speed_down = (uint8_t)1
}Speed_Change_t;

//驱动模式
typedef enum
{
    Drive_Mode_Single_4_Beats = (uint8_t)0, //单四拍
    Drive_Mode_Double_4_Beats = (uint8_t)1, //双四拍
    Drive_Mode_8_Beats        = (uint8_t)2  //八拍
}Drive_Mode_t;

//定义结构体类型
typedef struct
{
    Status_t Status;            //步进电机状态
    Direction_t Direction;      //步进电机方向
    Speed_t Speed;              //步进电机速度
    uint8_t Circle;             //步进电机转动圈数
    Drive_Mode_t Drive_Mode;    //步进电机驱动模式
    uint16_t Pulse_Cnt;         //步进电机脉冲计数(定时器计数)
    uint16_t one_Circle_Pulse;  //步进电机转动一圈的脉冲数

    void (*Start_Or_Stop)(void);
    void (*Direction_Adjust)(void);
    void (*Speed_Adjust)(Speed_Change_t );
    void (*Step_One_Puls)(void);
}Uniplar_Step_Motor_t;

/* extern variables-----------------------------------------------------------*/
extern Uniplar_Step_Motor_t Uniplar_Step_Motor;
/* extern function prototypes------ -------------------------------------------*/ 

#endif
/********************************************************
  End Of File
********************************************************/
